import { SerialPort } from 'serialport'

//
/**
 * 获取串口列表
 * @returns Promise
 */
export const getList = () => {
  return SerialPort.list()
}

/**
 * 打开串口
 * @returns connectSerialPort
 */
export const openSerialPort = (options, openCallback) => {
  return new SerialPort(options, openCallback)
}

// 关闭串口
export const closeSerialPort = (e) => {}

// 向串口写入数据
export const serialPortWrite = (data) => {
  console.log('发送数据', data)
  serialport.write(data)
}

// 接收串口数据
export const receiveSerialPortData = (e) => {
  serialport.on('data', (data) => {
    console.log('收到数据', data)
    e.reply('SerialPort-receiveData', res)
  })
}
